#ifndef SYNC_H
#define SYNC_H

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <pthread.h>
#include <fcntl.h>
#include <semaphore.h>
#include "backup.h"

#define MAX_PATH_LENGTH 256
#define MAX_THREADS 10 //最多10个线程
#define FILE_MAX 500 * 1024 * 1024
#define BUFFER_SIZE 1024
#define THREAD_COUNT 4

typedef struct {
    char source[MAX_PATH_LENGTH];
    char destination[MAX_PATH_LENGTH];
    int mode; // 1: B to A, 2: A to B, 3: AB bidirectional
} SyncJob;

void draw_progress_bar(); 

void *copy_bigfile_thread_sync(void* arg); //大文件的写入线程

void copy_file_sync(const char* source_file, const char* dest_file);

int has_dirent(const char* directory_path, const struct dirent* entry_to_find);

void delete_older_file(const char* file_path1, const char* file_path2);

void delete_directory(const char* path); //删除整个目录，包括其中的子目录和子文件

void backup_diectory_sync(const char* source, const char* destination);

void sync_directory(char* source, char* destination, int mode);//只负责清扫两个目录

void* sync_directory_thread(void* arg);


#endif